package thread;

public class MemoryTest {
    public static void printMemoInfo(){
        System.out.print("Xmx=");
        System.out.println(Runtime.getRuntime().maxMemory()/1024.0/1204+"M");

        System.out.print("free mem=");
        System.out.println(Runtime.getRuntime().freeMemory()/1024.0/1204+"M");

        System.out.print("total mem=");
        System.out.println(Runtime.getRuntime().totalMemory() /1024.0/1204+"M");
    }


    public static void main(String[] args) {
        System.out.println("目前如下：");
        printMemoInfo();
        byte[] b = new byte[1*1024*1024];
        System.out.println("分配了1M空间给数组");
        printMemoInfo();
        byte[] d = new byte[4*1024*1024];
        System.out.println("分配了4M空间给数组");
        printMemoInfo();

        System.gc();
        System.out.println("内存回收");
        printMemoInfo();
    }
}
